home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / comm / tcp / socklink100.lha / socklink / RawIN.h < prev    next >
C/C++ Source or Header  |  1994-08-21  |  16KB  |  371 lines

  1. #ifndef RAWIN_H
  2. #define RAWIN_H
  3.  
  4. /*  $Filename: RawIN.h $
  5. **  $Release: 1.2 $
  6. **  $Date: August 21, 1994 $
  7. **  $Author: Sam Yee (samy@sfu.ca | 1:153/765) $
  8. **
  9. **  Header file for RawIN.lib
  10. **
  11. **  Freely redistributable if this file is unmodified.
  12. */
  13.  
  14. #include <exec/types.h>
  15. #include <dos/dosextens.h>
  16. #include <dos/dos.h>
  17.  
  18. #define REG(x)          register __ ## x
  19. #define ASM             __asm
  20.  
  21. #define RAWIN_NAME  "rawin.library" /* name of library */
  22.  
  23. /*
  24. *********************************************************************
  25. ** structures
  26. *********************************************************************
  27. */
  28.  
  29. struct Line
  30. {
  31.     UBYTE           *buf,           /* buffer for command line */
  32.                     lastchar,       /* last input character */
  33.                     InputChar;      /* incoming character */
  34.     UWORD           flags;          /* flags, look below */
  35.     ULONG           bufindex,       /* index into buf */
  36.                     buflen,         /* length of current command line */
  37.                     bufmax,         /* max length of buffer */
  38.                     hist_linesmax,  /* maximum number of history lines */
  39.                     hist_linecount, /* as of right now, the number of lines */
  40.                     hist_lineindex; /* current history line */
  41.     struct History  *hist_head,     /* first history line */
  42.                     *hist_tail;     /* last history line */
  43.     struct MsgPort  *ReadReplyPort; /* input handler talks to us through here */
  44.     struct StandardPacket   read_packet; /* for packet reads */
  45.  
  46.     /* new for 1.2 */
  47.     LONG            hist_lownum;    /* lowest history number in list */
  48.     BPTR            InputStream,    /* ADOS file handle, default Input()/Output() */
  49.                     OutputStream;   /* if NULL, all i/o functions will be ignored */
  50.         /* output callback stuff */
  51.     LONG    (*callback)(APTR,UBYTE *,LONG);  /* output callback function, you set it! */
  52.     APTR    callback_io_block;      /* io block ptr for callback() function */
  53.     LONG    callback_result;        /* result of call will be stored here */
  54.         /* callback_result = callback(callback_io_block,buf,buflen)
  55.                              buf = character buffer, buflen = buffer length */
  56.     UBYTE           *BreakStr,      /* string to display when ^C has been hit,
  57.                                        default is ***Break, NULL for none */
  58.                     *PauseStr,      /* string to display when RI_PauseKey() is called
  59.                                        and user presses the pause key
  60.                                        default is [PAUSED], NULL for none */
  61.                     *no_str,        /* The string No, used by RI_AskNoYes() and
  62.                                        RI_AskYesNo() */
  63.                     *yes_str;       /* The string Yes, used by the same routines */
  64.     LONG            tab_spaces,     /* number of characters per tab, if 0 no tabs.
  65.                                        default 8. */
  66.                     prompt_len,     /* length of your prompt */
  67.                     no_key,         /* key to cause RI_AskNoYes() to return TRUE */
  68.                     yes_key;        /* key to cause RI_AskYesNo() to return TRUE */
  69.     struct MsgPort  *WriteReplyPort; /* input handler talks to us through here */
  70.     struct StandardPacket   write_packet; /* for packet writes */
  71.     APTR            write_buffer;   /* copied from RI_StartWriteRequest */
  72.     LONG            write_length;   /* likewise */
  73. };
  74.  
  75. #define LNF_ANSI        (1<<0)  /* user's terminal support ANSI control codes?
  76.                                    you may set this flag, else CSI sets it */
  77. #define LNF_CSI         (1<<1)  /* control sequence introducer seen. */
  78. #define LNF_RAWMODE     (1<<2)  /* if on, we are in raw mode. */
  79. #define LNF_STARTEDREAD (1<<3)  /* if on, we've requested a read. *read only* */
  80. #define LNF_EOF         (1<<4)  /* if on, end-of-file on InputStream. *read only* */
  81. #define LNF_BREAKC      (1<<5)  /* I've received a signal C (break) */
  82. #define LNF_STARTEDWRITE (1<<6) /* if on, we've requested a write. *read only* */
  83. #define LNF_READERROR   (1<<7)  /* read error */
  84. #define LNF_WRITEERROR  (1<<8)  /* write error */
  85.  
  86. /* history node */
  87. struct History
  88. {
  89.     struct History  *last,  /* previous history line */
  90.                     *next;  /* next history line */
  91.     UBYTE           *buf;   /* buffer of the history line */
  92.     ULONG           buflen; /* length of this history line */
  93. };
  94.  
  95.  
  96. /*******************************************************************/
  97. #ifdef RAWIN_RUNTIME
  98. /*
  99. ** Startup/cleanup/init routines
  100. */
  101.  
  102. struct Line *       /* returns allocated Line structure, NULL == failure */
  103. RI_AllocLine(ULONG buf_size,   /* size of input buffer to allocate */
  104.              ULONG hist_size); /* number of history lines */
  105.  
  106. void    /* de-allocate a Line structure */
  107. RI_FreeLine(struct Line *line);
  108.  
  109. void    /* reset a Line (eg. initialize the indices, etc.) */
  110. RI_ResetLine(struct Line *line);
  111.  
  112. /*
  113. ** Misc. routines
  114. */
  115.  
  116. /* set stdout to raw mode */
  117. void
  118. RI_SetMode(struct Line *line,      /* line allocated with AllocLine() */
  119.            BOOL        raw);       /* TRUE == rawmode, FALSE == cooked mode */
  120.  
  121. /* start the next raw read */
  122. void
  123. RI_SendReadRequest(struct Line *line);
  124.  
  125. void
  126. RI_SendWriteRequest(struct Line *line,
  127.                     APTR        buffer,  /* what to write */
  128.                     LONG        length); /* how much to write,
  129.                                             -1L == use strlen(buffer) */
  130.  
  131. BOOL    /* returns non-zero if user has pressed CR or LF */
  132. RI_BuildLine(struct Line   *line,      /* line to build */
  133.              LONG          max_chars,  /* # of characters for this command line,
  134.                                           -1 == default */
  135.              BOOL          echo);      /* if TRUE, output changes to command line */
  136.  
  137. BOOL /* check for a keypress.  if TRUE, a key has been typed */
  138. RI_KeyPressed(struct Line *line);
  139.  
  140.  
  141. BOOL /* write completed? */
  142. RI_WriteDone(struct Line *line);
  143.  
  144. void
  145. RI_WaitWrite(struct Line *line);
  146.  
  147. /*
  148. ** History routines
  149. */
  150.  
  151. void
  152. RI_AddHistory(struct Line *line,
  153.               UBYTE       *buf,       /* history buffer to add */
  154.               LONG        max_chars); /* length of buffer to add, if -1 use default (strlen()) */
  155.  
  156. struct History *    /* returns pointer to History, else NULL on failure */
  157. RI_GetHistory(struct Line  *line,      /* line to get history from */
  158.               LONG         num);       /* history line # */
  159.  
  160. void
  161. RI_ShowHistory(struct Line *line,
  162.                LONG        hist_start, /* start listing history lines from this location,
  163.                                           1 is the beginning, -1 is the end. */
  164.                LONG        hist_lines, /* # of history lines to display, -1L == all */
  165.                BOOL        reverse);   /* if TRUE then reverse order of output */
  166.  
  167. void
  168. RI_DeleteHistory(struct Line   *line,  /* line to delete history*/
  169.                  LONG          num);   /* history # to delete, 1 is the first, -1 is the last */
  170.  
  171.  
  172. /*
  173. ** Input routines
  174. */
  175.  
  176. LONG /* -1L == read unsuccessful due to EOL or break.
  177.         0L == user only pressed return, else the # of chars read */
  178. RI_Gets(struct Line     *line,
  179.         UBYTE           *buf,     /* buffer to store command line, if NULL use line->buf */
  180.         ULONG           buflen,   /* length of buffer */
  181.         ULONG           defsize,  /* default size of buffer to display */
  182.         BOOL            hot,      /* hotkey if true, returns when a key is hit. */
  183.         BOOL            caps,     /* CAPS if true */
  184.         BOOL            echo);    /* if TRUE, output keypresses */
  185.  
  186. LONG    /* key user pressed, else -1 */
  187. RI_PauseKey(struct Line    *line,
  188.             LONG           pause_key,      /* key to press to go into paused mode. -1 is any */
  189.             LONG           unpause_key);   /* key to press to return from pause mode. -1 is any */
  190.  
  191. LONG    /* if greater than or equal to 0 then the user has typed a character */
  192. RI_GetKey(struct Line *line,
  193.           BOOL        caps,   /* if TRUE, capitalize input */
  194.           BOOL        echo);  /* if TRUE, echo input */
  195.  
  196. LONG    /* if greater than or equal to 0 then the user has typed a character,
  197.            else read line->flag for reason. */
  198. RI_WaitKey(struct Line    *line,
  199.            BOOL           caps,   /* if TRUE, capitalize input */
  200.            BOOL           echo);  /* if TRUE, echo input */
  201.  
  202. BOOL /* did user select No? */
  203. RI_AskNoYes(struct Line    *line,
  204.             BOOL           verbose);   /* Display Yes/No accordingly? */
  205.  
  206. BOOL /* did user select Yes? */
  207. RI_AskYesNo(struct Line    *line,
  208.             BOOL           verbose);   /* Display Yes/No accordingly? */
  209.  
  210. LONG /* number of characters read, 0 for none */
  211. RI_GetBlock(struct Line *line,
  212.             BOOL        caps,   /* if TRUE, capitalize input */
  213.             BOOL        echo,   /* if TRUE, echo input */
  214.             void        *buffer, /* location to store input */
  215.             LONG        length); /* maximum we can read */
  216.  
  217.  
  218. #pragma libcall RawINBase RI_AllocLine 1E 1002
  219. #pragma libcall RawINBase RI_FreeLine 24 801
  220. #pragma libcall RawINBase RI_ResetLine 2A 801
  221. #pragma libcall RawINBase RI_SetMode 30 0802
  222. #pragma libcall RawINBase RI_SendReadRequest 36 801
  223. #pragma libcall RawINBase RI_BuildLine 3C 10803
  224. #pragma libcall RawINBase RI_KeyPressed 42 801
  225. #pragma libcall RawINBase RI_AddHistory 48 19803
  226. #pragma libcall RawINBase RI_GetHistory 4E 0802
  227. #pragma libcall RawINBase RI_ShowHistory 54 210804
  228. #pragma libcall RawINBase RI_DeleteHistory 5A 0802
  229. #pragma libcall RawINBase RI_Gets 60 543219807
  230. #pragma libcall RawINBase RI_GetKey 66 10803
  231. #pragma libcall RawINBase RI_WaitKey 6C 10803
  232. #pragma libcall RawINBase RI_PauseKey 72 10803
  233. #pragma libcall RawINBase RI_AskNoYes 78 0802
  234. #pragma libcall RawINBase RI_AskYesNo 7E 0802
  235. #pragma libcall RawINBase RI_GetBlock 84 2A10805
  236. #pragma libcall RawINBase RI_SendWriteRequest 8A 19803
  237. #pragma libcall RawINBase RI_WriteDone 90 801
  238. #pragma libcall RawINBase RI_WaitWrite 96 801
  239.  
  240. /*******************************************************************/
  241.  
  242. #else /* we want to the linked library includes */
  243.  
  244. /*******************************************************************/
  245. /* initialization/exit routines */
  246. ASM struct Line *       /* returns allocated Line structure, NULL == failure */
  247. RI_AllocLine(REG(d0)   ULONG buf_size,   /* size of input buffer to allocate */
  248.              REG(d1)   ULONG hist_size); /* number of history lines */
  249.  
  250. ASM void                /* de-allocate a Line structure */
  251. RI_FreeLine(REG(a0)    struct Line *line);
  252.  
  253. ASM void                /* reset a Line (eg. initialize the indices, etc.) */
  254. RI_ResetLine(REG(a0)   struct Line *line);
  255.  
  256. /*
  257. ** Misc. routines
  258. */
  259.  
  260. /* set stdout to raw mode */
  261. ASM void
  262. RI_SetMode(REG(a0) struct Line *line,   /* line allocated with AllocLine */
  263.            REG(d0) BOOL        raw);    /* TRUE == rawmode, FALSE == cooked mode */
  264.  
  265. /* start the next raw read */
  266. ASM void
  267. RI_SendReadRequest(REG(a0)  struct Line *line);
  268.  
  269. /* start the next write */
  270. ASM void
  271. RI_SendWriteRequest(REG(a0) struct Line *line,
  272.                     REG(a1) APTR        buffer,  /* what to write */
  273.                     REG(d1) LONG        length); /* how much to write */
  274.  
  275. ASM BOOL    /* returns non-zero if user has pressed CR or LF */
  276. RI_BuildLine(REG(a0)   struct Line   *line,      /* line to build */
  277.              REG(d0)   LONG          max_chars,  /* # of characters for this command line,
  278.                                                     -1 == default */
  279.              REG(d1)   BOOL          echo);      /* if TRUE, output changes to command line */
  280.  
  281. ASM BOOL /* check for a keypress.  if TRUE, a key has been typed */
  282. RI_KeyPressed(REG(a0)  struct Line *line);
  283.  
  284.  
  285. ASM BOOL /* write completed? */
  286. RI_WriteDone(REG(a0)  struct Line *line);
  287.  
  288. ASM void
  289. RI_WaitWrite(REG(a0)  struct Line *line);
  290.  
  291.  
  292. /*
  293. ** History routines
  294. */
  295.  
  296. ASM void
  297. RI_AddHistory(REG(a0) struct Line *line,
  298.               REG(a1) UBYTE       *buf,         /* history buffer to add */
  299.               REG(d1) LONG        max_chars);   /* length of buffer to add,
  300.                                                    if -1 use default (strlen()) */
  301.  
  302. ASM struct History *    /* returns pointer to History, else NULL on failure */
  303. RI_GetHistory(REG(a0)  struct Line  *line,      /* line to get history from */
  304.               REG(d0)  LONG         num);       /* history line # */
  305.  
  306. ASM void
  307. RI_ShowHistory(REG(a0) struct Line *line,
  308.                REG(d0) LONG        hist_start, /* start listing history lines from this location,
  309.                                                   1 is the beginning, -1 is the end. */
  310.                REG(d1) LONG        hist_lines, /* # of history lines to display, -1L == all */
  311.                REG(d2) BOOL        reverse);   /* if TRUE then reverse order of output */
  312.  
  313. ASM void
  314. RI_DeleteHistory(REG(a0)   struct Line   *line,  /* line to delete history*/
  315.                  REG(d0)   LONG          num);   /* history # to delete, 1 is the first,
  316.                                                     -1 is the last */
  317.  
  318.  
  319. /*
  320. ** Input routines
  321. */
  322.  
  323. ASM LONG /* -1L == read unsuccessful due to EOL or ^C break.
  324.             0L == user only pressed return, else the # of chars read */
  325. RI_Gets(REG(a0) struct Line *line,
  326.         REG(a1) UBYTE       *buf,       /* buffer to store command line,
  327.                                            if NULL use line->buf */
  328.         REG(d1) ULONG       buflen,     /* length of buffer */
  329.         REG(d2) ULONG       defsize,    /* default size of buffer to display */
  330.         REG(d3) BOOL        hot,        /* hotkey if true, returns when a key is hit. */
  331.         REG(d4) BOOL        caps,       /* CAPS if true */
  332.         REG(d5) BOOL        echo);      /* if TRUE, output keypresses */
  333.  
  334. ASM LONG    /* key user pressed, else -1 */
  335. RI_PauseKey(REG(a0) struct Line    *line,
  336.             REG(d0) LONG           pause_key,       /* key to press to go into paused mode.
  337.                                                        -1 is any */
  338.             REG(d1) LONG           unpause_key);   /* key to press to return from pause mode.
  339.                                                       -1 is any */
  340.  
  341. ASM LONG    /* if greater than or equal to 0 then the user has typed a character, else error */
  342. RI_GetKey(REG(a0) struct Line *line,
  343.           REG(d0) BOOL        caps,     /* if TRUE, capitalize input */
  344.           REG(d1) BOOL        echo);    /* if TRUE, echo input */
  345.  
  346. ASM LONG    /* if greater than 0 then the user has typed a character, else read line->flag
  347.                for reason. */
  348. RI_WaitKey(REG(a0) struct Line  *line,
  349.            REG(d0) BOOL         caps,   /* if TRUE, capitalize input */
  350.            REG(d1) BOOL         echo);  /* if TRUE, echo input */
  351.  
  352. ASM BOOL /* did user select No? */
  353. RI_AskNoYes(REG(a0) struct Line *line,
  354.             REG(d0) BOOL        verbose);   /* Display Yes/No accordingly? */
  355.  
  356. ASM BOOL /* did user select Yes? */
  357. RI_AskYesNo(REG(a0) struct Line    *line,
  358.             REG(d0) BOOL           verbose);   /* Display Yes/No accordingly? */
  359.  
  360. ASM LONG /* number of characters read, 0 for none */
  361. RI_GetBlock(REG(a0) struct Line *line,
  362.             REG(d0) BOOL        caps,   /* if TRUE, capitalize input */
  363.             REG(d1) BOOL        echo,   /* if TRUE, echo input */
  364.             REG(a2) void        *buffer, /* location to store input */
  365.             REG(d2) LONG        length); /* maximum we can read */
  366.  
  367. #endif  /* RAWIN_RUNTIME */
  368.  
  369. /*******************************************************************/
  370. #endif  /* RAWIN_H */
  371.